import {
    getSearchResAPI
} from '../../api/search';
import {
    GETDANQURES,
    GETGESHOURES,
    GETZHUANJIRES,
    GETGEDANRES
} from '../constants';

// 单曲 -- 5 分别截取数据长度
export const getDanquSearchResAction = (key) => {
    return async (dispatch) => {
        let res;
        try {
            res= await getSearchResAPI(key, 1); // 单曲 -- 5 分别截取数据长度
        } catch (error) {
            console.log(error);
        }
        const data = res.data.result.songs;
        dispatch({
            type: GETDANQURES,
            data
        });
        return data;
    }
}
export const getGeshouSearchResAction = (key) => {
    return async (dispatch) => {
        let res;
        try {
            res= await getSearchResAPI(key, 100); // 歌手 --1
        } catch (error) {
            console.log(error);
        }
        const data = res.data.result.artists;
        dispatch({
            type: GETGESHOURES,
            data
        });
        return data;
    }
}
export const getZhuanjiSearchResAction = (key) => {
    return async (dispatch) => {
        let res;
        try {
            res= await getSearchResAPI(key, 10); // 专辑 --2;
        } catch (error) {
            console.log(error);
        }
        const data = res.data.result.albums;
        dispatch({
            type: GETZHUANJIRES,
            data
        });
        return data;
    }
}
export const getGedanSearchResAction = (key) => {
    return async (dispatch) => {
        let res;
        try {
            res= await getSearchResAPI(key, 1000); // 歌单 --2
        } catch (error) {
            console.log(error);
        }
        const data = res.data.result.playlists;
        dispatch({
            type: GETGEDANRES,
            data
        });
        return data;
    }
}